<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上课倒计时</title>
    <script src="vue.js"></script>
    <style>
        .container {
            background: rgba(255,255,255,.5);
            width: 600px;
            height: 400px;
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            padding: 10px;
            border-radius: 10px;
            text-align: center;
        }

        h1 {
            color: #DE4848;
            font-size: 60px;
            font-family: '宋体';
        }

        .figure,
        .divider {
            font-size: 80px;
            color: #DE4848;
            font-weight: 700;
        }

        .divider {
            font-size: 100px;
            margin: 0 10px;
        }

        .figure {
            background-image: linear-gradient(to bottom,#F0F0F0,#fff,#F0F0F0);
            border-radius: 10px;
            padding: 10px;
        }
    </style>
</head>

<body>
    <div id="app" class="container">
        <h1>{{title}}</h1>
        <div class="time">
            <span class="figure">{{hours}}</span>
            <span class="divider">:</span>
            <span class="figure">{{minutes}}</span>
            <span class="divider">:</span>
            <span class="figure">{{seconds}}</span>
        </div>
    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            title:'上课倒计时',
            hours: '00',
            minutes: '00',
            seconds: '00',
            // 休息时长: 单位分钟
            duration: 15,
            timerId: 0
        },
        methods: {
            countDown() {
                this.hours = Math.floor(this.duration / 3600).toString().padStart(2, 0);
                this.minutes = Math.floor(this.duration % 3600 / 60).toString().padStart(2, 0);
                this.seconds = Math.floor(this.duration % 3600 % 60).toString().padStart(2, 0);
            }
        },
        created() {
            this.duration = parseInt(prompt('请输入休息时长, 单位分钟', 15))*60;
            this.timerId = setInterval(() => {
                this.countDown();
                if (this.duration === 0) {
                    clearInterval(this.timerId);
                    this.title="开始上课";
                }
                this.duration -= 1;
            }, 1000);
        }
    });
</script>

</html>